package com.byt.consultation.utils;

import android.text.TextUtils;

import com.byt.base.utils.TimeUtil;
import com.byt.common.adapter.lv.LvViewHolder;
import com.byt.common.adapter.rv.RvViewHolder;
import com.byt.common.bean.ConsultaBean;
import com.byt.common.image.ImageLoaderUtils;
import com.byt.consultation.R;

public class AdapterDataUtils {

    /**
     * 加载患者列表的数据
     */
//    public static void loadPatientData(RvViewHolder holder, PatientBean patient, int position) {
//        ImageLoaderUtils.displayCircle(holder.getView(R.id.img_patient_pic), patient.getPhoto_src(), R.drawable.default_touxiang, R.drawable.default_touxiang);
//        if (TextUtils.isEmpty(patient.getMember_remark())) {
//            holder.setText(R.id.tv_patient_name, patient.getNick_name());
//        } else {
//            holder.setText(R.id.tv_patient_name, patient.getMember_remark());
//        }
//        holder.setText(R.id.tv_patient_gestational, patient.getMember_status());
//        switch (patient.getActivate_state()) {
//            case 1://未激活
//                holder.setImageResource(R.id.img_patient_state, R.drawable.ic_patient_activation);
//                holder.setText(R.id.tv_patient_state, "未激活");
//                holder.setTextColorRes(R.id.tv_patient_state, R.color.color_999999);
//                break;
//            case 2://首次激活
//                holder.setImageResource(R.id.img_patient_state, R.drawable.ic_patient_first);
//                holder.setText(R.id.tv_patient_state, "首次激活");
//                holder.setTextColorRes(R.id.tv_patient_state, R.color.color_ffc15a);
//                break;
//            case 3://已激活
//                holder.setImageResource(R.id.img_patient_state, R.drawable.ic_patient_activated);
//                holder.setText(R.id.tv_patient_state, "已激活");
//                holder.setTextColorRes(R.id.tv_patient_state, R.color.main_color);
//                break;
//        }
//    }

    /**
     * 加载咨询列表的数据
     */
    public static void loadConsultaData(RvViewHolder holder, ConsultaBean consulta, int position) {
        ImageLoaderUtils.displayCircle(holder.getView(R.id.img_patient_pic), consulta.getPhoto_src(), R.drawable.default_touxiang, R.drawable.default_touxiang);
        if (TextUtils.isEmpty(consulta.getMember_remark())) {
            holder.setText(R.id.tv_patient_name, consulta.getNick_name());
        } else {
            holder.setText(R.id.tv_patient_name, consulta.getMember_remark());
        }
        if (consulta.getStyle() == 1) {
            holder.setImageResource(R.id.img_patient_state, R.drawable.expert_home_inquiry);
        } else {
            holder.setImageResource(R.id.img_patient_state, R.drawable.expert_home_image);
        }
        holder.setVisible(R.id.v_read_state, consulta.getRead_flag() == 0);
        holder.setText(R.id.tv_patient_problem, consulta.getContent());
        holder.setText(R.id.tv_problem_time, TimeUtil.getfriendlyUseTime(consulta.getDialogue_datetime() * 1000));
        if (consulta.getState() == 1) {
            if (consulta.getReply_flag() == 1) {
                // 已回复
                if (consulta.getReply_end_datetime() < System.currentTimeMillis() / 1000) {
                    //回复时间小于当前时间 已解决
                    holder.setText(R.id.tv_problem_state, "已解决");
                    if (consulta.getSummary_flag() == 0) {
                        holder.setVisible(R.id.tv_summary_state, true);
                        holder.setText(R.id.tv_summary_state, "未总结");
                    } else {
                        holder.setVisible(R.id.tv_summary_state, false);
                    }
                } else {
                    //咨询中
                    holder.setText(R.id.tv_problem_state, "咨询中");
                    holder.setVisible(R.id.tv_summary_state, false);
                }
            } else {
                // 未回复
                if (consulta.getEnd_datetime() < System.currentTimeMillis() / 1000) {
                    //私人咨询时间小于当前时间 已失效
                    holder.setText(R.id.tv_problem_state, "已失效");
                    holder.setVisible(R.id.tv_summary_state, false);
                } else {
                    //咨询中
                    holder.setText(R.id.tv_problem_state, "咨询中");
                    holder.setVisible(R.id.tv_summary_state, false);
                }
            }
        } else if (consulta.getState() == 2) {
            //已失效
            holder.setText(R.id.tv_problem_state, "已失效");
            holder.setVisible(R.id.tv_summary_state, false);
        } else if (consulta.getState() == 3) {
            //已解决
            holder.setText(R.id.tv_problem_state, "已解决");
            if (consulta.getSummary_flag() == 0) {
                holder.setVisible(R.id.tv_summary_state, true);
                holder.setText(R.id.tv_summary_state, "未总结");
            } else {
                holder.setVisible(R.id.tv_summary_state, false);
            }
        }
        // 费用类型, 1：免费 2：付费
        if (consulta.getOutlay_type() == 1) {
            holder.setText(R.id.tv_problem_price, "免费");
        } else {
            holder.setText(R.id.tv_problem_price, consulta.getPrice() + "元");
        }
    }

    /**
     * 加载咨询列表的数据
     */
    public static void loadConsultaData(LvViewHolder holder, ConsultaBean consulta, int position) {
        ImageLoaderUtils.displayCircle(holder.getView(R.id.img_patient_pic), consulta.getPhoto_src(), R.drawable.default_touxiang, R.drawable.default_touxiang);
        if (TextUtils.isEmpty(consulta.getMember_remark())) {
            holder.setText(R.id.tv_patient_name, consulta.getNick_name());
        } else {
            holder.setText(R.id.tv_patient_name, consulta.getMember_remark());
        }
        if (consulta.getStyle() == 1) {
            holder.setImageResource(R.id.img_patient_state, R.drawable.expert_home_inquiry);
        } else {
            holder.setImageResource(R.id.img_patient_state, R.drawable.expert_home_image);
        }
        holder.setVisible(R.id.v_read_state, consulta.getRead_flag() == 0);
        holder.setText(R.id.tv_patient_problem, consulta.getContent());
        holder.setText(R.id.tv_problem_time, TimeUtil.getfriendlyUseTime(consulta.getDialogue_datetime() * 1000));
        if (consulta.getState() == 1) {
            if (consulta.getReply_flag() == 1) {
                // 已回复
                if (consulta.getReply_end_datetime() < System.currentTimeMillis() / 1000) {
                    //回复时间小于当前时间 已解决
                    holder.setText(R.id.tv_problem_state, "已解决");
                } else {
                    //咨询中
                    holder.setText(R.id.tv_problem_state, "咨询中");
                }
            } else {
                // 未回复
                if (consulta.getEnd_datetime() < System.currentTimeMillis() / 1000) {
                    //私人咨询时间小于当前时间 已失效
                    holder.setText(R.id.tv_problem_state, "已失效");
                } else {
                    //咨询中
                    holder.setText(R.id.tv_problem_state, "咨询中");
                }
            }
            holder.setVisible(R.id.tv_summary_state, false);
        } else if (consulta.getState() == 2) {
            //已失效
            holder.setText(R.id.tv_problem_state, "已失效");
            holder.setVisible(R.id.tv_summary_state, false);
        } else if (consulta.getState() == 3) {
            //已解决
            holder.setText(R.id.tv_problem_state, "已解决");
            if (consulta.getSummary_flag() == 0) {
                holder.setVisible(R.id.tv_summary_state, true);
                holder.setText(R.id.tv_summary_state, "未总结");
            } else {
                holder.setVisible(R.id.tv_summary_state, false);
            }
        }
        // 1：免费 2：付费
        if (consulta.getOutlay_type() == 1) {
            holder.setText(R.id.tv_problem_price, "免费");
        } else {
            holder.setText(R.id.tv_problem_price, consulta.getPrice() + "元");
        }
    }
}